package com.xierong.remoteplayerlauncher.recevier;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.xierong.remoteplayerlauncher.service.UDPListenerService;
import com.xierong.remoteplayerlauncher.utils.Def;
import com.xierong.remoteplayerlauncher.utils.PlayerManager;

public class UDPListenerRecevier extends BroadcastReceiver {
    private UDPCommand command;
    @Override
    public void onReceive(Context content, Intent intent) {
        String action = intent.getAction();
        Log.d(PlayerManager.TAG,"收到的ACTION：" + action);

        if (action.equals(UDPListenerService.UDP_RECEIVER)) {
            String cmd = intent.getExtras().getString("action");
            Log.d(PlayerManager.TAG, "收到的command：" + command);
            switch(cmd) {
                case Def.PLAY: {
                    command.UDP_Play();
                }break;
                case Def.PAUSE: {
                    command.UDP_Pause();
                }break;
                case Def.LOOP: {
                    command.UDP_Loop();
                }break;
                case Def.RESTART: {
                    command.UDP_Restart();
                }break;
                case Def.VOL_UP: {
                    command.UDP_Volup();
                }break;
                case Def.VOL_DOWN: {
                    command.UDP_Voldown();
                }break;
                case Def.PREV: {
                    command.UDP_Prev();
                }break;
                case Def.NEXT: {
                    command.UDP_Next();
                }
            }
        }
    }
    public interface UDPCommand {
        void UDP_Play();
        void UDP_Pause();
        void UDP_Restart();
        void UDP_Loop();
        void UDP_Volup();
        void UDP_Voldown();
        void UDP_Prev();
        void UDP_Next();
    }
    public void setUdpListener(UDPCommand command) {
        this.command = command;
    }
}
